//#include "bq_sample.h"
//#include "BQ769xx.h"
//#include <stdio.h>
//#include "main.h"

//static uint8_t getMaxBatNum(void){
//	uint8_t max_batnum_support = 0;//支持的最大电芯数
//	uint8_t bq_makeup_mode = get_bq_makeup_mode();//获取bq的成组方式
//	if(bq_makeup_mode == bq76920_only){
//		max_batnum_support = 5;
//	}else if(bq_makeup_mode == bq76930_only){
//		max_batnum_support = 10;
//	}else if(bq_makeup_mode == bq76940_only){
//		max_batnum_support = 15;
//	}else if(bq_makeup_mode == bq76930_two){
//		max_batnum_support = 20;
//	}else if(bq_makeup_mode == bq76930_940){
//		max_batnum_support = 25;
//	}
//	
//	return max_batnum_support;
//}

//static uint32_t get_effective_channel_bit(uint8_t batNum){
//	uint32_t cell_valid_bit = 0xffffffff;
//	uint8_t bq_makeup_mode = get_bq_makeup_mode();//获取bq的成组方式
//	if(bq_makeup_mode == bq76920_only){
//		cell_valid_bit &= 0x1f;
//		if(batNum == 4){
//			cell_valid_bit &= 0x17;//第4串无效
//		}else if(batNum == 3){
//			cell_valid_bit &= 0x13;//第3、4串无效
//		}
//	}else if(bq_makeup_mode == bq76930_only){
//		cell_valid_bit &= 0x3ff;
//		if(batNum == 9){
//			cell_valid_bit &= 0x2ff;//第9串无效
//		}else if(batNum == 8){
//			cell_valid_bit &= 0x2f7;//第4、9串无效
//		}else if(batNum == 7){
//			cell_valid_bit &= 0x277;//第4、8、9串无效
//		}else if(batNum == 6){
//			cell_valid_bit &= 0x273;//第3、4、8、9串无效
//		}
//	}else if(bq_makeup_mode == bq76940_only){
//		cell_valid_bit &= 0x7fff;
//		if(batNum == 14){
//			cell_valid_bit &= 0x5fff;//第14串无效
//		}else if(batNum == 13){
//			cell_valid_bit &= 0x5eff;//第14、9串无效
//		}else if(batNum == 12){
//			cell_valid_bit &= 0x5ef7;//第14、9、4串无效
//		}else if(batNum == 11){
//			cell_valid_bit &= 0x4ef7;//第4、9、13、14串无效
//		}else if(batNum == 10){
//			cell_valid_bit &= 0x4e77;//第4、8、9、13、14串无效
//		}else if(batNum == 9){
//			cell_valid_bit &= 0x4e73;//第3、4、8、9、13、14串无效
//		}
//	}else if(bq_makeup_mode == bq76930_two){
//		cell_valid_bit &= 0x0fffff;
//		if(batNum == 19){
//			cell_valid_bit &= 0x0bffff;//第19串无效
//		}else if(batNum == 18){
//			cell_valid_bit &= 0x0bdfff;//第14、19串无效
//		}else if(batNum == 17){
//			cell_valid_bit &= 0x09dfff;//第14、18、19串无效
//		}else if(batNum == 16){
//			cell_valid_bit &= 0x09cfff;//第13、14、18、19串无效
//		}else if(batNum == 15){
//			cell_valid_bit &= 0x09ceff;//第9、13、14、18、19串无效
//		}else if(batNum == 14){
//			cell_valid_bit &= 0x09cef7;//第4、9、13、14、18、19串无效
//		}else if(batNum == 13){
//			cell_valid_bit &= 0x09ce77;//第4、8、9、13、14、18、19串无效
//		}
//	}else if(bq_makeup_mode == bq76930_940){
//		cell_valid_bit &= 0x01ffffff;
//	}
//	
//	return cell_valid_bit;
//}

//static uint32_t get_bal_limit_result(uint8_t batNum,uint8_t maxVolNum,uint32_t needBalState){
//	uint32_t softBalState = 0x00;
//	softBalState |= 1u<<(maxVolNum - 1);
//	int8_t i = maxVolNum - 2;
//	while(i > 0){
//		if((needBalState>>(i-1))&0x01){
//			softBalState |= 1u<<(i - 1);
//			i -= 2;
//		}else{
//			i --;
//		}
//	}
//	i = maxVolNum + 2;
//	while(i <= batNum){
//		if((needBalState>>(i-1))&0x01){
//			softBalState |= 1u<<(i - 1);
//			i += 2;
//		}else{
//			i ++;
//		}
//	}
//	return softBalState;
//}

//static uint32_t get_bq_physical_bal_channel(uint32_t batNum,uint32_t softBalState){
//	uint8_t max_batnum_support = getMaxBatNum();//支持的最大电芯数
//	uint32_t cell_valid_bit = get_effective_channel_bit(batNum);
//	uint32_t bqBalBit = 0x00000000;
//	uint8_t valid_index = 0;
//	for(uint8_t i = 0;i<max_batnum_support;i++){
//		if((cell_valid_bit>>i)&0x01){//如果采样通道有效
//			if ((softBalState >> valid_index) & 0x01) {
//				bqBalBit |= (1 << i);
//			}else {
//				bqBalBit |= (0 << i);
//			}
//			valid_index ++;
//		}
//	}
//	return bqBalBit;
//}


//void bq_timeout_deal(void){
//	bq_irq_timeout_deal();
//}

//BQ_SYS_CTRL_REG_STATUS bq_get_status(void){
//	bq769x0_update_status();
//	return get_bq769x0_status(); 
//}

//int32_t bq_get_current(void){
//	int32_t batCur = 0;
//	bq769x0_read_rsense_vol(&batCur);
//	
//	return batCur;
//}

//void bq_get_cell_vol(uint8_t batNum,uint16_t *volArray){
//	uint8_t max_batnum_support = getMaxBatNum();//支持的最大电芯数
//	uint8_t bq_makeup_mode = get_bq_makeup_mode();//获取bq的成组方式
//	uint16_t tempVol[32] = {0};
//	if(bq_makeup_mode == bq76920_only){
//		max_batnum_support = 5;
//		bq769x0_read_vol(BQ_DOWN,&tempVol[0]);
//	}else if(bq_makeup_mode == bq76930_only){
//		max_batnum_support = 10;
//		bq769x0_read_vol(BQ_DOWN,&tempVol[0]);
//	}else if(bq_makeup_mode == bq76940_only){
//		max_batnum_support = 15;
//		bq769x0_read_vol(BQ_DOWN,&tempVol[0]);
//	}else if(bq_makeup_mode == bq76930_two){
//		max_batnum_support = 20;
//		bq769x0_read_vol(BQ_DOWN,&tempVol[0]);
//		bq769x0_read_vol(BQ_UP,&tempVol[10]);
//	}else if(bq_makeup_mode == bq76930_940){
//		max_batnum_support = 25;
//		bq769x0_read_vol(BQ_DOWN,&tempVol[0]);
//		bq769x0_read_vol(BQ_UP,&tempVol[10]);
//	}
//	uint32_t cell_valid_bit = get_effective_channel_bit(batNum);
//	uint8_t cell_index = 0;
//	for(uint8_t i = 0;i<max_batnum_support;i++){
//		if(cell_valid_bit & (1 << i)){
//			volArray[cell_index ++] = tempVol[i];
//		}
//	}
//}

////包含bq本身均衡规则限制计算和有短接情况下的均衡位和实际位对应的转换
//uint32_t bq_balance_open(uint8_t batNum,uint8_t maxVolNum,uint32_t needBalState){
//	////获取bq成组方式，得到支持的最大通道数
//	uint8_t max_batnum_support = getMaxBatNum();//支持的最大电芯数
//	uint32_t softBalState = get_bal_limit_result(batNum,maxVolNum,needBalState);//通过限制规则，得出的允许均衡的位
//	//将规则运算后的均衡位与bq实际通道对应的运算
//	uint32_t bqBalBit = get_bq_physical_bal_channel(batNum,softBalState);
//	uint8_t bq_makeup_mode = get_bq_makeup_mode();//获取bq的成组方式
//	if(bq_makeup_mode == bq76920_only){
//		bq769x0_balance_ctrl(BQ_DOWN,bqBalBit&0x1f);
//	}else if(bq_makeup_mode == bq76930_only){
//		bq769x0_balance_ctrl(BQ_DOWN,bqBalBit&0x3ff);
//	}else if(bq_makeup_mode == bq76940_only){
//		bq769x0_balance_ctrl(BQ_DOWN,bqBalBit&0x7fff);
//	}else if(bq_makeup_mode == bq76930_two){
//		bq769x0_balance_ctrl(BQ_DOWN,bqBalBit&0x3ff);
//		bq769x0_balance_ctrl(BQ_UP,(bqBalBit>>10)&0x3ff);
//	}else if(bq_makeup_mode == bq76930_940){
//		bq769x0_balance_ctrl(BQ_DOWN,bqBalBit&0x3ff);
//		bq769x0_balance_ctrl(BQ_UP,(bqBalBit>>10)&0x7fff);//高侧940
//	}
//	return softBalState;
//}

//void bq_balance_close(void){
//	uint8_t bq_makeup_mode = get_bq_makeup_mode();//获取bq的成组方式
//	if(bq_makeup_mode == bq76920_only){
//		bq769x0_balance_ctrl(BQ_DOWN,0x0000);
//	}else if(bq_makeup_mode == bq76930_only){
//		bq769x0_balance_ctrl(BQ_DOWN,0x0000);
//	}else if(bq_makeup_mode == bq76940_only){
//		bq769x0_balance_ctrl(BQ_DOWN,0x0000);
//	}else if(bq_makeup_mode == bq76930_two){
//		bq769x0_balance_ctrl(BQ_DOWN,0x0000);
//		bq769x0_balance_ctrl(BQ_UP,0x0000);
//	}else if(bq_makeup_mode == bq76930_940){
//		bq769x0_balance_ctrl(BQ_DOWN,0x0000);
//		bq769x0_balance_ctrl(BQ_UP,0x0000);
//	}
//}

//void bq_set_SCD(uint16_t curVol,uint16_t delay){
//	bq769x0_set_SCD(curVol,delay);
//}

//void bq_set_OCD(uint16_t curVol,uint16_t delay){
//	bq769x0_set_OCD(curVol,delay);
//}

//void bq_set_OV_UV_Delay(uint8_t odelay,uint8_t udelay){
//	bq769x0_set_OV_UV_Delay(odelay,udelay);
//}

//void bq_set_OV_UV(uint16_t overVol,uint16_t underVol){
//	bq769x0_set_OV_UV(overVol,underVol);
//}

//void bq_sleep_enter(void){
//	bq_balance_close();
//	bq769x0_sleep_enter();
//	hc32_pin_write(MCU_KZ_BQ_POWER,PIN_LOW);
//}

//void bq_sleep_exit(void){
//	hc32_pin_write(MCU_KZ_BQ_POWER,PIN_HIGH);
//	bq769x0_sleep_exit();
//}
